﻿using System;

using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Common;
using Micronet.OpenWeb.Entity;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.Sub
{
    public partial class OpenCommunityRegister : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CleatText();

            if (!Page.IsPostBack)
            {

                if (OwCommunityFieldOfActivitiesBLL.OwGetByDynamic().Count > 0)
                {


                ActivitiesCbb.DataSource = OwCommunityFieldOfActivitiesBLL.OwGetByDynamic();
                ActivitiesCbb.DataBind();


                }


            }

        }

        void CleatText()
        {
            NameTxt.Text = "";
            TradeNameTxt.Text = "";
            DescriptionGrow.Text = "";

        }


        protected void OwOpenCommunityTypeCbb_Init(object sender, EventArgs e)
        {

            OwComboBox cbb = sender as OwComboBox;

            cbb.OwDataSourceBindFromType<OwEnum.CompanyTypes>(useLanguage: false);
        }

        protected void IAcceptCb_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void RegisterBt_Click(object sender, EventArgs e)
        {


            OwOpenCommunityProfileDetailsEntity profileDetails = new OwOpenCommunityProfileDetailsEntity();
            profileDetails.Name = NameTxt.Text;
            profileDetails.Description = DescriptionGrow.Text;



            OwOpenCommunityProfilesInFieldOfActivitiesEntity inFieldOfActivitiesEntity = new OwOpenCommunityProfilesInFieldOfActivitiesEntity();
            inFieldOfActivitiesEntity.CommunityFieldOfActivityID = ActivitiesCbb.SelectedValue.OwToInt64TryParseReturn0();
            inFieldOfActivitiesEntity.CommunityProfileDetailID = OwOpenCommunityProfileDetailsBLL.OwSave(profileDetails).OwToInt64TryParseReturn0();
            OwOpenCommunityProfilesInFieldOfActivitiesBLL.OwSave(inFieldOfActivitiesEntity);


            OwOpenCommunityProfilesEntity profiles = new OwOpenCommunityProfilesEntity();
            profiles.TradeName = TradeNameTxt.Text;
            profiles.CommunityTypeID = OwOpenCommunityTypeCbb.SelectedValue.OwToInt64TryParseReturn0();
            profiles.DateTimeEstablished = DateOfEstablishmentDtpk.SelectedDate;
            OwOpenCommunityProfilesBLL.OwSave(profiles);

            
        }

        protected void ResetBt_Click(object sender, EventArgs e)
        {
            CleatText();
        }

    }
}